package org.example;

import com.alibaba.fastjson.JSON;
import com.entity.TbClass;
import com.entity.User;
import com.mapper.TbClassMapper;
import com.mapper.UserMapper;
import com.util.ResponseUtil;
import com.util.SqlSessionUtil;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;

@WebServlet(name = "tbClass", value = "/tbClass/list")
public class TestTbClassServlet extends HttpServlet {

    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {

        String code = request.getParameter("code");


        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        TbClassMapper tbClassMapper = sqlSession.getMapper(TbClassMapper.class);

        Map<String, String> param = new HashMap<String, String>();
        param.put("classCode", code);
        TbClass tbClass = tbClassMapper.selectTbClassByCode(param);
        System.out.println(JSON.toJSONString(tbClass));


        ResponseUtil.doPrint(response, JSON.toJSONString(JSON.toJSONString(tbClass)));
    }

    public void destroy() {
    }
}